<?php

namespace Common\Model;

use Think\Model;

class MemberActivityModel extends Model
{

    protected $_validate = array();

    protected $_auto = array(
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('update_time', NOW_TIME, self::MODEL_BOTH),
    );

    /**
     * 新增或更新
     *
     * @return boolean fasle 失败 ， int 成功 返回完整的数据
     */
    public function update($data)
    {
        $data = $this->create($data);
        if (empty($data)) {
            return false;
        }
        if (empty($data['id'])) {
            $id = $this->add();
            if (!$id) {
                $this->error = '新增出错';
                return false;
            }
        } else {
            $result = $this->where(array('id' => $data['id']))->save($data);
            if (false === $result) {
                $this->error = '更新出错';
                return false;
            }
        }

        return $data;
    }

}
